<template>
	<view class="wrap">
		<head-box></head-box>
		<view class="xin_body">
			<view class="xin_title">{{type===1?'请对本次活动进行评价':'请对本次奉献进行评价'}}</view>
			<view class="xin">
				<sx-rate :value="0" :max="5"  @change="onChange" />
			</view>
			<view class="message">
				 <textarea cursorSpacing="10"  class="uni-textarea" v-model="text"
                   :placeholder="type==1?'请输入您对此次活动的评价(可空)':'请输入您对此次奉献的评价(可空)'" />
			</view>
			 <button type="primary" class="sub" @tap="onsub">确定评价</button>
		</view>
		<tabs-box></tabs-box>
	</view>
</template>
<script>
	import { movedateComment,adviseComment } from '@/api/comment';
	export default {
		data() {
			return {
				type:'1',
				moveId:'',
				text:'',
				xin_num:0,
			};
		},
		onLoad(options) {
			if(!!options.id)
			{
				this.moveId = options.id;
			}
			if(!!options.type)
			{
				this.type = options.type;
			}
		},
    onShow(){
      // #ifdef H5
      console.log('分享')
      this.$wxSetShare()
      // #endif
    },
		methods: {
		  //评论活动切换
			onChange(e){
			  this.xin_num = e;
			},
      //进行评价操作
			onsub()
			{
				var that = this
				if(that.xin_num == 0)
				{
					this.$api.msg('星级评价不能为空');
					return;
				}
				let params ={}
				if(that.type==1)
				{
					params ={"comment":that.text,"commentStar": that.xin_num,"moveId": that.moveId}
					movedateComment(params).then(res => {
						if(res.success)
						{
							this.$api.msg("评价成功");
							setTimeout(() => {
								uni.navigateBack();
							}, 1000);
						}
						else
						{
							this.$api.msg(res.message);
							setTimeout(() => {
								uni.navigateBack();
							}, 1000);
						}
					});
				}
				else
				{
					params ={"comment":that.text,"commentStar": that.xin_num,"adviseId": that.moveId}
					adviseComment(params).then(res => {
						if(res.success)
						{
							this.$api.msg("评价成功");
							setTimeout(() => {
								uni.navigateBack();
							}, 1000);
						}
						else
						{
							this.$api.msg(res.message);
							setTimeout(() => {
								uni.navigateBack();
							}, 1000);
						}
					});
				}
			}
		}
	};
</script>
<style lang="scss">
	.wrap {
		.xin_body{
			padding: 90rpx;
			.xin_title{
				font-size: 42rpx;
				margin-bottom: 17rpx;
				text-align: center;
			}
			.xin{
				width: 360rpx;
				font-size: 60rpx;
				margin: 0 auto;
			}
			.uni-textarea{
				margin-top: 60rpx;
				border: 1px solid #cccccc;
				width: 570rpx;
				padding: 20rpx;
				border-radius: 20rpx;
			}
			.sub{
				margin-top: 60rpx;
			}
		}

	}

</style>
